package com.alibaba.incubator.loadtestermini.model.measurement.recorder;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.incubator.loadtestermini.model.measurement.report.InteractionResult;
import com.alibaba.incubator.loadtestermini.model.measurement.report.SceneMeasurement;

/**
 * thread-safe<br/>
 * (created at 2010-5-27)
 * 
 * @author <a href="mailto:shuo.qius@alibaba-inc.com">QIU Shuo</a>
 */
public class SceneRecorder {
    private volatile Long errorTime;

    public SceneRecorder setErrorOccur() {
        errorTime = System.currentTimeMillis();
        return this;
    }

    public boolean isErrorOccur() {
        return errorTime == null;
    }

    public List<SceneMeasurement> getRecords() {
        return records;
    }

    /** not thread-safe */
    private List<SceneMeasurement> records = new ArrayList<SceneMeasurement>();
    public volatile long lastSnapshotTime = System.currentTimeMillis();

    public void startRecord() {
        lastSnapshotTime = System.currentTimeMillis();
    }

    //------------------------------------------------------------------------------
    public void addInteractionRestul(InteractionResult item) {
        final long endTime = item.getEndTime();
        final long startTime = item.getStartTime();
        final boolean succ = item.isSuccess();
        final long resp = (endTime - startTime) >= 0 ? (endTime - startTime) : 0;
//QS_TODO
        
    }
    /**
     * called by scene, which is single-thread
     */
    public void snapshot() {
        snapshoting=true;
        //QS_TODO
        snapshoting=false;
    }
    private volatile boolean snapshoting=false;
 

}
